#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

vector<string> ans;
string path;
bool check[12] = { false };
void dfs(string s)
{
    if (path.size() == s.size())
    {
        ans.push_back(path);
        return;
    }
    for (int i = 0; i < s.size(); i++)
    {
        if (i > 0 && s[i] == s[i - 1] && check[i - 1] == false) continue;
        if (check[i] == true) continue;

        path.push_back(s[i]);
        check[i] = true;
        dfs(s);
        path.pop_back();
        check[i] = false;
    }
}
vector<string> Permutation(string str) 
{
    sort(str.begin(), str.end());
    dfs(str);
    return ans;
}

int main()
{
    string s = "aab";
    vector<string> ret = Permutation(s);
    for (int i = 0; i < ret.size(); i++)
    {
        cout << "\"" << ret[i] << "\" ";
    }
    return 0;
}